
<template>
  <div class="product">
    <div style="display: flex;align-items: center;font-size: 28rpx;padding: 16rpx 24rpx;background-color: #ffffff;margin: 24rpx 0 12rpx 0">
      <div class="back-icon" @click="toBack">
        <u-icon name="arrow-left" size="28" color="#fff"></u-icon>
      </div>
      您可以选择以下
      <span style="padding: 0 4px;color: darkred">{{ count }}</span>
      款礼品兑换
    </div>
    <div style="padding: 16rpx" v-if="productList.length > 1">
      <u-row gutter="12">
        <u-col span="6" v-for="item in productList" :key="item.id">
          <div class="list-item" @click="toDetail(item)">
            <div class="vote-img" :style="{ backgroundImage: 'url(' + item.post_url + ')'}">
            </div>
            <div class="vote-text">
              <div class="vote-name">
                {{ item.name }}
              </div>
              <div class="vote-desc">
                商品编号：{{ item.code }}
              </div>
            </div>
          </div>
        </u-col>
      </u-row>
    </div>
    <div style="padding: 16rpx" v-if="productList.length === 1">
      <div class="product-content" v-for="item in productList" :key="item.id">
        <div class="product-image" :style="{ backgroundImage: 'url(' + item.post_url + ')'}">
        </div>
        <div class="right-detail">
          <div class="product-name">{{ item.name }}</div>
          <div class="product-code">商品编号：{{ item.code }}</div>
          <div style="display: flex;align-items: center;justify-content: flex-end">
            <div class="detail-button"  @click="toDetail(item)">查看详情</div>
          </div>
        </div>
      </div>
    </div>
    <u-empty v-if="productList.length === 0"></u-empty>
  </div>
</template>
<script>
export default {
  name: "index",
  data() {
    return {
      productList: [],
      detail: {
        productList: []
      },
      count: 0
    }
  },
  onLoad({ pid }) {
    this.$api.getProductList({
      pid,
    }).then(res => {
      console.log(res)
      this.productList = res
      this.count = res.length
    })
  },
  methods: {
    toDetail(item) {
      this.$u.route({
        type: 'navigateTo',
        url: '/pages/product/detail?id=' + item.id
      })
    }
  }
}
</script>

<style scoped lang="scss">
.product {
  width: 100%;
  max-width: 750px;
  margin: 0 auto;
  height: 100%;
  .list-item {
    border-radius: 12rpx;
    background-color: #ffffff;
    overflow: hidden;
    margin-bottom: 24rpx;
    box-shadow: 0px 3px 4px 0px rgba(0,0,0,.07);
    .vote-img {
      width: 100%;
      height: 0;
      padding-bottom: 100%;
      border-radius: 6px 6px 0px 0px;
      background: no-repeat;
      background-size: 100% 100%;
    }
    .vote-text {
      display: flex;
      flex-direction: column;
      align-items: center;
      text-align: center;
      padding: 6rpx 0;
      .vote-name {
        font-size: 12px;
        margin-bottom: 12rpx;
      }
    }
    .vote_number {
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 16px;
      line-height: 34px;
      color: #333333;
      .vote_number_text2 {
        color: rgba(133, 107, 223,1);
      }
    }
    .vote-button-right {
      width: 100%;
      margin-top: 30rpx;
      font-size: 28rpx;
      padding: 12rpx 0;
      background-color: rgb(112, 76, 237);
      border-radius: 12rpx;
      text-align: center;
      color: #ffffff;
    }

    .vote-button {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 80%;
      margin: 12rpx auto 0;
      color: #ffffff;
      height: 40rpx;
      text-align: center;
      .vote-button-left {
        flex: 1;
        font-size: 28rpx;
        padding: 10rpx 0;
        background-color: rgba(94, 185, 94, 0.26);
        color: rgba(133, 107, 223,1);
        margin-right: -40rpx;
        border-bottom-left-radius: 20rpx;
        border-top-left-radius: 20rpx;
      }
    }
    .list-icon {
      height: 220rpx;
      width: 100%;
    }
    .list-text {
      padding:0 20rpx;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 100%;
      .list-title {
        font-size: 28rpx;
        color: #000000;
        margin-bottom: 14rpx;
        text-align: center;
      }
      .list-desc {
        font-size: 24rpx;
        color: #999999;
        margin-bottom: 14rpx;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
  }
  .product-content {
    height: 128px;
    border-radius: 8px;
    padding: 10px;
    background-color: #fff;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    .product-image {
      width: 108px;
      height: 108px;
      border-radius: 8px;
      border: 1px solid #f0f3f8;
      background: no-repeat;
      background-size: 100% 100%;
    }
  }
  .right-detail {
    width: 200px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
    justify-content: space-around;
  }
  .product-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    height: 45px;
    font-size: 16px;
    font-weight: 400;
    color: #333;
    line-height: 22px;
  }
  .product-code {
    font-size: 12px;
    color: #b7b7b7;
  }
  .detail-button {
    width: 100px;
    color: rgb(255, 255, 255);
    background: rgb(101, 89, 255);
    height: 30px;
    line-height: 30px;
    border-radius: 14px;
    text-align: center;
  }
}
</style>
